package io.wit.modules.sys.service.impl;

import io.wit.common.annotation.DataFilter;
import io.wit.modules.sys.dao.SysRoleDao;
import io.wit.modules.sys.entity.SysRoleEntity;
import io.wit.modules.sys.service.SysRoleMenuService;
import io.wit.modules.sys.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 角色
*/
@Service("sysRoleService")
public class SysRoleServiceImpl implements SysRoleService {

    @Autowired
	private SysRoleDao sysRoleDao;

    @Autowired
	private SysRoleMenuService sysRoleMenuService;

	@Override
	public SysRoleEntity queryObject(Long roleId) {
		return sysRoleDao.queryObject(roleId);
	}

	@Override
	@DataFilter(tableAlias = "r", user = false)
	public List<SysRoleEntity> queryList(Map<String, Object> map) {
		return sysRoleDao.queryList(map);
	}

	@Override
	@DataFilter(tableAlias = "r", user = false)
	public int queryTotal(Map<String, Object> map) {
		return sysRoleDao.queryTotal(map);
	}

	@Override
	@Transactional
	public void save(final SysRoleEntity role) {
		sysRoleDao.save(role);
		//保存角色与菜单关系
		sysRoleMenuService.saveOrUpdate(role.getRoleId(), role.getMenuIdList());
	}

	@Override
	@Transactional
	public void update(final SysRoleEntity role) {
		sysRoleDao.update(role);
		//更新角色与菜单关系
		sysRoleMenuService.saveOrUpdate(role.getRoleId(), role.getMenuIdList());
	}

	@Override
	@Transactional
	public void deleteBatch(Long[] roleIds) {
		sysRoleDao.deleteBatch(roleIds);
	}

    @Override
    public List<SysRoleEntity> getListRole(final Map<String,Object> map){
        return sysRoleDao.getListRole(map);
    }
}